package com.cardone.platform.usercenter.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.context.Contexts;
import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.usercenter.dto.UsDepartmentTranslateDto;
import com.cardone.platform.usercenter.service.UsDepartmentTranslateService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 用户部门调动
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/usercenter/usDepartmentTranslate/")
@Controller
public class UsDepartmentTranslateController {

	/**
	 * 用户部门调动：删除
	 * 
	 * @param deleteUsDepartmentTranslate
	 *            用户部门调动对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
  public Callable<ReturnDataDto<String>> deleteJson(final UsDepartmentTranslateDto deleteUsDepartmentTranslate) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsDepartmentTranslateService.class).deleteByIds(deleteUsDepartmentTranslate);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户部门调动：编辑
	 * 
	 * @param findUsDepartmentTranslate
	 *            用户部门调动对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<UsDepartmentTranslateDto>> findByIdJson(final UsDepartmentTranslateDto findUsDepartmentTranslate, final Model model) {
		return new Callable<ReturnDataDto<UsDepartmentTranslateDto>>() {
			@Override
			public ReturnDataDto<UsDepartmentTranslateDto> call() throws Exception {
				try {
					final UsDepartmentTranslateDto usDepartmentTranslate = ContextHolder.getBean(UsDepartmentTranslateService.class).findById(UsDepartmentTranslateDto.class, findUsDepartmentTranslate);

					return ReturnDataUtils.newReturnData(usDepartmentTranslate);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsDepartmentTranslateController.log);
				}
			}
		};
	}

	/**
	 * 用户部门调动：分页查询
	 * 
	 * @param paginationUsDepartmentTranslate
	 *            用户部门调动对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
  public Callable<ReturnDataDto<PaginationDto<UsDepartmentTranslateDto>>> paginationByLikeCodeJson(final UsDepartmentTranslateDto paginationUsDepartmentTranslate) {
		return new Callable<ReturnDataDto<PaginationDto<UsDepartmentTranslateDto>>>() {
			public ReturnDataDto<PaginationDto<UsDepartmentTranslateDto>> call() throws Exception {
				try {
					final PaginationDto<UsDepartmentTranslateDto> usDepartmentTranslatePagination = ContextHolder.getBean(UsDepartmentTranslateService.class).paginationByLikeCode(UsDepartmentTranslateDto.class, paginationUsDepartmentTranslate);
				
					return ReturnDataUtils.newReturnData(usDepartmentTranslatePagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户部门调动：分页查询
	 * 
	 * @param paginationUsDepartmentTranslate
	 *            用户部门调动对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
  public void paginationHtml(final UsDepartmentTranslateDto paginationUsDepartmentTranslate, final Model model) {
		final PaginationDto<UsDepartmentTranslateDto> usDepartmentTranslatePagination = ContextHolder.getBean(UsDepartmentTranslateService.class).paginationByLikeCode(UsDepartmentTranslateDto.class, paginationUsDepartmentTranslate);
		
		model.addAttribute("usDepartmentTranslatePagination", usDepartmentTranslatePagination);
	}
	
	/**
	 * 用户部门调动：分页查询
	 * 
	 * @param findUsDepartmentTranslate
	 *            用户部门调动对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
  public void editHtml(final UsDepartmentTranslateDto findUsDepartmentTranslate, final Model model) {
		final UsDepartmentTranslateDto usDepartmentTranslate = ContextHolder.getBean(UsDepartmentTranslateService.class).findById(UsDepartmentTranslateDto.class, findUsDepartmentTranslate);
		
		model.addAttribute("usDepartmentTranslate", usDepartmentTranslate);
	}

	/**
	 * 用户部门调动：查询
	 * 
	 * @param findListUsDepartmentTranslate
	 *            用户部门调动对象
	 * @return 用户部门调动对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
  	public Callable<ReturnDataDto<List<UsDepartmentTranslateDto>>> findListByLikeCodeJson(final UsDepartmentTranslateDto findListUsDepartmentTranslate) {
		return new Callable<ReturnDataDto<List<UsDepartmentTranslateDto>>>() {
			public ReturnDataDto<List<UsDepartmentTranslateDto>> call() throws Exception {
				try {
					final List<UsDepartmentTranslateDto> usDepartmentTranslateList = ContextHolder.getBean(UsDepartmentTranslateService.class).findListByLikeCode(UsDepartmentTranslateDto.class, findListUsDepartmentTranslate);
				
					return ReturnDataUtils.newReturnData(usDepartmentTranslateList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户部门调动：保存
	 * 
	 * @param saveUsDepartmentTranslate
	 *            用户部门调动对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
  public Callable<ReturnDataDto<String>> saveJson(final UsDepartmentTranslateDto saveUsDepartmentTranslate) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsDepartmentTranslateService.class).saveByIdOrCode(UsDepartmentTranslateDto.class, saveUsDepartmentTranslate);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}
}
